#include <bits/stdc++.h>
using namespace std;

// #define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
	{                                         \
		cerr << "\033[32;1m" << #x << " -> "; \
		err(x);                               \
	}
void err()
{
	cerr << "\033[39;0m" << endl;
}
template <typename T, typename... A>
void err(T a, A... x)
{
	cerr << a << ' ';
	err(x...);
}
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 3e5 + 50;

int t, n;

typedef pair<int, int> P;

P a[N];

int d[N];

P dat[N << 2];
int dcnt;

int main(int argc, char const *argv[])
{
	scanf("%d", &t);
	for (int kk = 0; kk < t; ++kk)
	{
		scanf("%d", &n);
		for (int i = 0; i < n; ++i)
			scanf("%d%d", &a[i].first, &a[i].second);
		
		memset(d, 0, sizeof(int) * n);
		dcnt = 0;
		for (int i=0; i<n; ++i)
		{
			dat[dcnt++] = make_pair(a[i].first, i);
			dat[dcnt++] = make_pair(a[i].second+1, -i-1);
		}
		
		sort(dat, dat+dcnt);
		// int cur = 0;
		set<int> S;
		int init = 0;
		for (int i=0; i<dcnt; ++i)
		{

			int id;
			if (dat[i].second >= 0)
			{
				id = dat[i].second;
				if (S.size() == 1)
				{
					++d[*S.begin()];
				}
				else if (S.size() == 0)
				{
					--d[id];
					++init;
				}
				
				S.insert(id);
			}
			else
			{
				id = -dat[i].second-1;
				S.erase(id);
			}	
		}

		int maxv = -1e9;
		for (int i=0; i<n; ++i)
			maxv = max(maxv, d[i]);

		for (int i=0; i<n; ++i)
			dbg(i, d[i]);
		
		printf("%d\n", maxv + init);

	}
	return 0;
}